<?php

class Backend extends MY_Controller {

    public function __construct() {
	parent::__construct();

	$this->initialization();
    }

    public function initialization() {
	$this->check_login();

	$this->set_layout('backend/layout_view');

	$this->load_stylesheets(array('global', 'form', 'z-lib', 'backend_layout'));

	$this->load_javascripts(array('jquery', 'jquery.tmpl', 'lib', 'backend_layout'));

	$this->set_javascript_variable('SITE_URL', SITE_URL);

	$this->set_javascript_variable('LANG', 'zh');

	$this->set_javascript_variable('USER_ID', intval($this->session->userdata('g_user_id')));

	$this->set_title('筑奥设计管理后台');
    }

    private function check_login() {
	if (intval($this->session->userdata('g_user_id')) <= 0) {
	    if ($this->input->is_ajax_request()) {
		$this->json_back('XT004');
	    } else {
		$login_url = SITE_URL . '/index.php/backend/auth/index';
		header("Location: {$login_url}");
		exie(0);
	    }
	}
    }

    public function index(){
	$this->load->view('backend/index');
    }

    public function header(){
	$this->set_layout('simple_layout');
	$this->rend('backend/header');
    }
    
    public function navigation(){
	$this->set_layout('simple_layout');
	$this->rend('backend/header');
    }
	
}
